package net.zigin.nhi.could.waste.converter;

/**
 * 请用一句话说明
 *
 * @author mgw1986
 * @version V1.0
 * @date 2020-09-03 21:15
 */

import net.zigin.commons.util.DateUtil;
import net.zigin.commons.util.StringUtil;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.util.Date;

/**
 * 字符串转日期参数转换器
 *
 * @author mgw1986
 * @date 2020/09/03 23:11
 */
@Component
public class StringToDateConverter implements Converter<String, Date> {

    @Override
    public Date convert(String dateStr) {
        if (StringUtil.isNullOrEmpty(dateStr)) {
            return null;
        }
        try {
            return DateUtil.parseDatePattern(dateStr);
        } catch (ParseException e) {
            return null;
        }
    }
}
